package q1;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.*;

public class AwesomeSocket {
	
	Socket mySocket;
	
	public AwesomeSocket(String IP, int port) {
		try {
			mySocket = new Socket(IP, port);
			BufferedReader dataIn = new BufferedReader( new InputStreamReader(System.in));
	         PrintWriter out = new PrintWriter(mySocket.getOutputStream(), true);
	         
	         
	         System.out.println( "DEBUG = " + mySocket.toString() + "  remotesocketadr = " + mySocket.getRemoteSocketAddress() );
	         
	         if( mySocket.isConnected() == false )
	         {
	        	 System.out.println( "SOCKET CONNECTION == FALSE" );
	         }
	         
	         System.out.println();
	         String text = "";
	         
	         do {
	        	 System.out.print("Enter String: ");
	        	 text = dataIn.readLine();
	        	 System.out.print("Sending string: '" + text + "'\n");
	        	 out.println(text);
	         } while (!text.equalsIgnoreCase("Exit"));
	         
	         out.close();
	         mySocket.close();
	         
		} catch(Exception e) {
			e.printStackTrace();
		}
	}

}
